#include "tcv_decthandle.h"
#include "tcv_dmhandle.h"
#include "Rk1808_dect/dectdatestruct.h"
#include "QDebug"

class _OutputLocalDate g_outputLocalDate;

TCV_DectHandle::TCV_DectHandle(QObject *i_dmhandle):
    m_DmHandle(i_dmhandle)
{

}

bool TCV_DectHandle::GetImage(cv::Mat &o_matPicture)
{
    return ((TCV_DMHandle*)m_DmHandle)->PopPictureFromInputQueue(1, o_matPicture);
}

bool TCV_DectHandle::OutputDectImage(cv::Mat i_matPicture)
{
    return ((TCV_DMHandle*)m_DmHandle)->CloneDectResToOutputQueue(i_matPicture);
}


void TCV_DectHandle::run()
{
    qDebug()<<"start dect";
    //dectFunc(this);
    qDebug()<<"finish dect";
    if(g_outputLocalDate.isDectSuccess == true)
        SN_DectFinish(1);
    else
        SN_DectFinish(0);
}

bool TCV_DectHandle::GetDectResult(cv::Point &t_point)
{
    if(g_outputLocalDate.isDectSuccess == true
            && g_outputLocalDate.point_num>0)
    {
        t_point.x = (g_outputLocalDate.point.at(0).x1
                     + g_outputLocalDate.point.at(0).x2)/2;
        t_point.y = (g_outputLocalDate.point.at(0).y1
                     + g_outputLocalDate.point.at(0).y2)/2;
        return true;
    }
    return false;
}
